$(document).ready(function () {
    // Add Ribbon Tab
    var addRibbonTab = "<div id='ribbon-tab' class='tab'><ul class='login'><li class='left'>&nbsp;</li><li class='login-content welcome-login'></li><li class='login-content sep'>|</li><li id='toggle' class='login-content'><a id='open' class='open'>Open Ribbon</a><a id='close' style='display: none;' class='close'>Close Ribbon</a></li><li class='right'>&nbsp;</li></ul> </div>";

    // Remove body attribute [scroll]
    $("body").removeAttr("scroll");

    // Remove Ribbon Panel Attribute [id] to prevent fixed height
    $("#s4-titlerow").removeAttr("id");

    // Remove Workspace panel attribute [id] to prevent panel scrolling"
    $("#s4-workspace").attr("id", "s4-workspace-autoscroll");

    // Remove class add custom class to view browse tab
    $(".ms-cui-tts-scale-2").removeClass().addClass("ms-cui-tts");

    // Add Ribbon Tab into Ribbon panel
    $("#s4-ribbonrow").append(addRibbonTab);

    // Ribbon Cookie Current state
    var ribbonCurrentState = $.cookie('ribbonCurrentState');
    var options = { path: '/', expires: 10 };

    // Expand Panel
    $("#open").click(function () {
        $("div#s4-ribboncont").slideDown("slow");
        $.cookie('ribbonCurrentState', 'expanded', options);
    });

    // Collapse Panel
    $("#close").click(function () {
        $("div#s4-ribboncont").slideUp("slow");
        $.cookie('ribbonCurrentState', 'collapsed', options);
    });

    // Switch buttons from 'Open Ribbon' to 'Close Ribbon' on click
    $("#toggle a").click(function () {
        $("#toggle a").toggle();
    });

    // Ribbon Cookie state
    if (ribbonCurrentState == null) {
        $.cookie('ribbonCurrentState', 'expanded', options);
    };
    if (ribbonCurrentState == 'collapsed') {
        $("div#s4-ribboncont").css({ 'display': 'none' });
        $("#close").css({ 'display': 'none' });
        $("#open").css({ 'display': 'block' });
    };
    if (ribbonCurrentState == 'expanded') {
        $("div#s4-ribboncont").css({ 'display': 'block' });
        $("#open").css({ 'display': 'none' });
        $("#close").css({ 'display': 'block' });
    };

});